package com.unei.guava.demo.bujingnian;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;

/**
 * Created by sunlei on 2015/1/22.
 */
public class MsgRuleBuilder {
    private Predicate<Msg> predicate;
    private boolean goon=false;

    public MsgRuleBuilder(Predicate<Msg> predicate) {
        this.predicate = predicate;
    }

    public static MsgRuleBuilder when(Predicate<Msg> predicate){
        return new MsgRuleBuilder(predicate);
    }

    public MsgRuleBuilder and(Predicate<Msg> one){
        predicate= Predicates.and(predicate,one);
        return this;
    }

    public MsgRuleBuilder or(Predicate<Msg> one){
        predicate=Predicates.or(predicate,one);
        return this;
    }

    public MsgRuleBuilder goon(){
        goon=true;
        return this;
    }

    public MsgRule then(Function<Msg,Msg> function){
        return new MsgRule(predicate,function,goon);
    }
}
